<template>
  <div class="agentlevel">
    <el-dialog :title="text" :visible.sync="dialogEdit" width="40%">
      <el-form ref="form" :model="form" size="medium" label-position="right">
        <el-row>
          <el-col :span="8" class="ban-left">代理商级别</el-col>
          <el-col :span="16"><el-form-item prop="agent_level"><el-input v-model="form.agent_level"></el-input></el-form-item></el-col>
        </el-row>
        <el-row>
          <el-col :span="8" class="ban-left">代理范围</el-col>
          <el-col :span="16"><el-form-item prop="agent_area"><el-input v-model="form.agent_area"></el-input></el-form-item></el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="ban-btn">
        <el-button @click="close">返 回</el-button>
        <el-button class="save" @click="ok('form')">保 存</el-button>
      </div>
    </el-dialog>
  </div>

</template>

<script>
export default {
  name: 'AgentEdit',
  props:{
    rows:{}
  },
  data() {
    return {
      text: '',
      dialogEdit: false,
      form: {
        agent_level: '',
        agent_area: ''
      }
    }
  },
  created() {
  },
  methods:{
    //编辑对话框
    openEdit() {
      this.text = "代理商等级编辑"
      this.dialogEdit = true;
      this.form = {
        agent_level: this.rows.agent_level,
        agent_area: this.rows.agent_area
      }
    },
    //新增对话框
    openAdd(){
      this.text = "新增代理商等级"
      this.dialogEdit = true;
    },

    close() {
      this.dialogEdit = false;
      this.form = {
        agent_level: '',
        agent_area: ''
      }
    },

    //保存表单
    ok () {
      this.$refs['form'].validate(valid => {
        if (valid) {
          console.log(this.form)
          this.dialogEdit = false;
          this.form = {
            agent_level: '',
            agent_area: ''
          }
          this.$message.success('保存成功')
        } else {
          this.$message.error('表单验证失败!')
        }
      })
    }
  }
}
</script>

<style>
</style>
